keepalived-install:
    file.managed:
        - name: /usr/local/src/keepalived-1.2.17.tar.gz
        - source: salt://prod/keepalived/files/keepalived-1.2.17.tar.gz
        - mode: 755
        - user: root
        - group: root

    cmd.run:
        - name: cd /usr/local/src && tar -zxf keepalived-1.2.17.tar.gz && cd keepalived-1.2.17 && ./configure --prefix=/usr/local/keepalived --disable-fwmark && make && make install
        - unless: test -d /usr/local/keepalived
        - require:
            - file: keepalived-install

{% if grains['os'] in ('Redhat','Centos') %}
{% set INITFILE='keepalived.init' %}
/etc/sysconfig/keepalived:
    file.managed:
        - source: salt://prod/keepalived/files/keepalived.sysconfig
        - mode: 644
        - user: root
        - group: root
{% else %}
{% set INITFILE='keepalived.init_debian' %}
{% endif %}

/etc/init.d/keepalived:
    file.managed:
        - source: salt://prod/keepalived/files/{{INITFILE}}
        - mode: 755
        - user: root
        - group: root

/etc/keepalived:
    file.directory:
        - user: root
        - group: root

/etc/keepalived/notify.sh:
    file.managed:
        - source: salt://prod/keepalived/files/notify.sh
        - mode: 755
        - user: root
        - group: root

